package cn.itsource.basic.base.controller;

import cn.itsource.basic.utli.AjaxResult;
import cn.itsource.basic.utli.FastDfsUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("fastDfs")
public class fastDfsController {
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file){
        try {
            //图片原始名称
            String originalFilename = file.getOriginalFilename();
            //获取后缀名称
            String extName = originalFilename.substring(originalFilename.indexOf(".")+1);
            //文件的路径
            String path = FastDfsUtil.upload(file.getBytes(), extName);
            //System.out.println(path);
            return AjaxResult.me().setResultObj(path);
        } catch (Exception e) {
            e.printStackTrace();
            return  AjaxResult.me().setMessage(e.getMessage());
        }
    }
}
